package com.example.skytakeoutserver.config

import com.example.serverbase.ext.Log
import com.example.skytakeoutserver.config.cpn.property.AliOSSProperty
import com.example.skytakeoutserver.util.AliOSSUtil
import lombok.RequiredArgsConstructor
import org.slf4j.LoggerFactory
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration


/**
 * 阿里OSS对象存储配置
 */
@Configuration
@RequiredArgsConstructor
class AliOSSConfig(
    private val aliOssProperties: AliOSSProperty
) {
    private val log = LoggerFactory.getLogger(AliOSSConfig::class.java)

    @Bean
    @ConditionalOnMissingBean
    fun aliOssUtil(): AliOSSUtil {
        Log.info("开始创建阿里云文件上传工具类对象{}", aliOssProperties)
        // 解析配置文件
        return AliOSSUtil(
            endpoint = aliOssProperties.endpoint!!,
            accessKeyId = aliOssProperties.accessKeyId!!,
            accessKeySecret = aliOssProperties.accessKeySecret!!,
            bucketName = aliOssProperties.bucketName!!,
            ignoreAuthToDebug = aliOssProperties.ignoreAuthToDebug!!,
        )
    }

}